<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%request.setAttribute("ctx", request.getContextPath());%>
<html>
<head>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="<%=request.getContextPath() %>/css/bootstrap.min.css">
    <link rel="stylesheet" href="<%=request.getContextPath() %>/css/bootstrap-theme.min.css">
    <link rel="stylesheet" href="<%=request.getContextPath() %>/css/theme.blue.css" type="text/css"></link>
    <script type="text/javascript" src="<%=request.getContextPath() %>/js/jquery-1.8.2.min.js"></script>
    <script type="text/javascript" src="<%=request.getContextPath() %>/js/jquery.validate.js"></script>
    <script type="text/javascript" src="<%=request.getContextPath() %>/js/my.js"></script>
    <script type="text/javascript" src="<%=request.getContextPath() %>/js/jquery.tablesorter.js"></script>
    <script type="text/javascript">
        /*js代码区*/
    </script>
</head>
<body>
<br>
<br>
<br>
<br>
<br>
<br>
<div class="col-md-12">
    <div class="page-header">
        <h2>
            <small>登录页面</small><br>
        </h2>
    </div>
    <div class="col-md-12">
        <form>
            用户名:<input type="text" name="username" id="username" onblur="checkUsername()"><br>
            密码 :<input type="text" name="password" id="password" onblur="checkPassword()"><br>
            <input type="button" value="登录" onclick="login()">
        </form>

    </div>
</div>
</body>
<script type="text/javascript">
    $("#myTable").tablesorter()

    /**
     * 用户名非空
     */
    function checkUsername() {
        var userName = $("#username").val();
        if (userName == null || userName == "") {

            alert("用户名不能为空");
        }
    }

    /**
     * 密码非空
     */
    function checkPassword() {
        var password = $("#password").val();
        if (password == null || password == "") {

            alert("密码不能为空");
        }
    }

    function login() {
        var user = {}

        user.username = $("#username").val();
        user.password = $("#password").val();

        $.ajax({
            url: "/user/login",
            data: JSON.stringify(user),
            type: "post",
            dataType: "json",
            contentType: "application/json;charset=UTF-8;",
            success: function (result) {
                if (result.status) {
                    alert("登录成功");
                    location.href = result.msg;
                } else {
                    alert(result.msg);
                }
            }
        })


    }

</script>
</html>